<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of configPeriodo
 *
 * @author drarko
 */
class configPeriodo extends table
{
    public function __construct() 
    {
        return parent::__construct("configPeriodo");
    }
    
    public function agregarPeriodo($valor,$autor)
    {
        $this->addValue("0");
        $this->addValue($valor);
        $this->addValue($this->fechaActual());
        
        $result = $this->insert();
        
        $log = new logConfiguracion();
        $log->alta($autor);
        
        return $result;
    }
    
    public function cambiarPeriodo($valor,$autor, $id = 1)
    {
        $log = new logConfiguracion();
        $log->modificacion($autor);

        $this->addSet("valor",$valor);
        $this->addWhere("id", $id);
    
        $result = $this->update();
        return $result;
    }
    
    public function verificarPeriodo()
    {
        $res = $this->select();
        foreach($res as $r)
        {
            $act = new DateTime(date("Y-m-d H:i:s"));
            $fecha = DateTime::createFromFormat("Y-m-d H:i:s", $r['fecha']);

            if($act >= $fecha)
                return 1;
            else
                return 0;
        }
        
    }
    
    public function reiniciarPeriodo($id,$autor)
    {
        $log = new logConfiguracion();
        $log->modificacion($autor);
        
        $this->addSet("fecha", $this->fechaActual());
        $this->addWhere("id", $id);
    
        $result = $this->update();
        return $result;        
    }
    
    public function borrar($id, $id_autor)
    {
        
        $log = new logDuenoDatosxGrupo();
        $log->baja($id_autor);
        
        return parent::borrar($id);
    }
}

